package net.hn.hnms.biz.safety.wind.Service;

import net.hn.hnms.biz.safety.wind.Dao.AirVolumeDao;
import net.hn.hnms.biz.safety.wind.entity.AirVolumeEntity;
import net.hn.hnms.biz.safety.wind.entity.AirVolumeVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @author 智呈物联 nzw
 * @date 2022/12/22
 */
@Service
public class AirVolumeService {

    private AirVolumeDao airVolumeDao;

    private PositionService positionService;

    @Autowired
    public void setAirVolumeDao(AirVolumeDao airVolumeDao) {
        this.airVolumeDao = airVolumeDao;
    }

    @Autowired
    public void setPositionService(PositionService positionService) {
        this.positionService = positionService;
    }

    public List<AirVolumeVO> findAirVolume(String mineCode){
        List<AirVolumeEntity> airVolumeEntityList = new ArrayList<>();
        List<Map<String,String>> mapList = airVolumeDao.findByPositionId(mineCode);
        for (Map<String,String> map : mapList){
            String positionId = map.get("position_id");
            Timestamp max = Timestamp.valueOf(map.get("max"));
            airVolumeEntityList.add(airVolumeDao.findByMaxDataTime(Long.parseLong(positionId),max));
        }

        List<AirVolumeVO> list = new ArrayList<>();
        for (AirVolumeEntity airVolumeEntity:airVolumeEntityList){
            AirVolumeVO airVolumeVO = new AirVolumeVO();
            airVolumeVO.setPositionName(positionService.getPositionName(airVolumeEntity.getPositionId()));
            airVolumeVO.setAirVolume(airVolumeEntity.getAirVolume());
            airVolumeVO.setWindSpeed(airVolumeEntity.getWindSpeed());
            list.add(airVolumeVO);
        }

        return list;
    }
}
